//
//  Syncdata.m
//  Bracelet
//
//  Created by Jayce on 15/3/5.
//  Copyright (c) 2015年 jing zhao. All rights reserved.
//

#import "Syncdata.h"

@implementation Syncdata

+(void)setSyncdataAPIWithUID:(NSString *)uid
              andAccessToken:(NSString *)accessToken
                headerDataWithUserName:(NSString *)userName
                success:(void (^)(NSString *msg)) successBlock
                     failure:(void (^)(NSError *error)) failureBlock{
    NSDictionary *data = @{@"uid":uid,@"access_token":accessToken};
    NSDictionary *header = @{@"BasicAuthUsername":userName};
    [[APIConnection shareInstance] post:@"syncdata/syncData_total" data:data header:header netError:^(NSError *error) {
        failureBlock(error);
    } apiFinish:^(id data) {
        NSDictionary *dic = data;
        NSInteger code = [[dic objectForKey:APIKEYCODE] integerValue];
        if (code == 0) {
            successBlock([dic objectForKey:APIKEYMSG]);
        }else{
            NSError * error= [NSError errorWithDomain:@"code" code:code userInfo:nil];
            failureBlock(error);
        }
    }];
}
@end
